package com.jzo2o.orders.dispatch.test.strategys;

import com.jzo2o.common.utils.CollUtils;
import com.jzo2o.orders.dispatch.model.dto.ServeProviderDTO;

import java.util.List;

/**
 * 规则处理器抽象类
 *
 * @Author mr.wu
 * @Date 2024-12-29 11:06
 */
public abstract class AbstractProcessRule implements IProcessRule {

    private IProcessRule next;

    public AbstractProcessRule(IProcessRule next) {
        this.next = next;
    }

    public abstract List<ServeProviderDTO> doFilter(List<ServeProviderDTO> serveProviderDTOList);

    /**
     * 指定下一个规则处理器
     *
     * @return
     */
    @Override
    public IProcessRule next() {
        return next;
    }

    /**
     * 根据初筛的服务人员列表，匹配规则中的逻辑找出符合要求的服务人员列表（细筛）
     *
     * @param serveProviderDTOList
     * @return
     */
    @Override
    public List<ServeProviderDTO> filter(List<ServeProviderDTO> serveProviderDTOList) {
        List<ServeProviderDTO> dtoList = this.doFilter(serveProviderDTOList);
        if(CollUtils.size(dtoList)>1 && next!=null) {
            return next.filter(dtoList);
        }
        return dtoList;
    }
}
